<template>
    <div class="uploadFile">
        <el-drawer
            width="500px"
            title="上传文件"
            :visible.sync="value"
            direction="rtl"
            :before-close="handleClose">
            <avue-form
                :option="options"
                v-model="form"
                :upload-after="uploadAfter">

            </avue-form>
        </el-drawer>
    </div>
</template>

<script>
import {getToken} from "@/utils/auth";
import {baseUrl} from "@/config";

export default {
    name: "upload-file",
    props: {
        value: {
            type: Boolean
        },
        folderPath: {
            type: String
        },
    },
    data() {
        return {
            form: {},
        }
    },
    computed: {
        options() {
            return {
                submitBtn: false,
                emptyBtn: false,
                column: [
                    {
                        label: '拖拽上传',
                        labelPosition: 'top',
                        prop: 'imgUrl',
                        type: 'upload',
                        span: 24,
                        dragFile: true,
                        action: `${baseUrl}/oss/upload`,
                        propsHttp: {
                            url: 'url',
                            name: 'name',
                            res: 'data'
                        },
                        headers: {
                            ['Authorization']: getToken()
                        },
                        data: {
                            folderPath: this.folderPath
                        },
                    },
                ]
            }
        }
    },
    methods: {
        handleClose(done) {
            this.$emit('input', false)
        },
        uploadAfter(res, done, loading, column) {
            console.log(res, column)
            this.$emit('getData')
            done()
        }
    }
}
</script>
<style lang='scss' scoped>
.uploadFile {
}
</style>